function showLoggedIn(id){
	if(id == null|| id.trim() == "true"){
		if($("[name=maxEntries]").val() == null){
			var line = 10;
		}else{
			var line = $("[name=maxEntries]").val();
		}
		if($("[name=selectpage]").val() == null){
			var pagePointer = 1; 
		}else{
			var pagePointer = $("[name=selectpage]").val(); 
		}
	}else if(id == "next"){
		var line = $("[name=maxEntries]").val();
		var pagePointer = parseInt($("[name=selectpage]").val())+1;
	}else if(id == "previous"){
		var line = $("[name=maxEntries]").val();
		var pagePointer = parseInt($("[name=selectpage]").val())-1;		
	}
	var link = "/loginService";
	var data = { func: "getlogin",offset: (line*pagePointer)-line,line: line,pagePointer: pagePointer}
	simpleservice(link,data,showLoggedInList);
}

function showLoggedInList(data){
	var objArray2 = new Array();
	objArray2 = JSON.parse(data);
	var sumtext = "";
	var text = "";
	var pageAmount = Math.ceil(objArray2[0]/objArray2[2]);
	var line = objArray2[2];
	var pagePointer = objArray2[1];
	var objArray = objArray2[3];
	$("#listsize").html("("+objArray.length+")");
	for(var i = 0;i< objArray.length+1;i++){
			if(i != objArray.length ){
				text = "<tr id=\"row_"+objArray[i]['id']+"\" style=\"border: 0px;\"> " +
						"<td id=\"col_1\" align=\"center\"> "+(i+1)+". </td>"+
						"<td><input type=\"checkbox\" id=\"id_"+i+"\" name=\"ids[]\" value=\""+objArray[i]['id']+"\"> </td>"+
						"<td align=\"left\" name=\"titleName\"> "+objArray[i].firstName+" </td>"+
						"<td align=\"center\">"+objArray[i].email+"</td>"+
						"<td align=\"center\"  >"+objArray[i].counterUser+"</td>"+
						"<td align=\"center\"  >"+objArray[i].lastStay+"</td>"+
						"<td align=\"center\"><a href=\"#\" onclick=\"changeStatusLoggedIn("+objArray[i]['id']+") \"> " +
						"<span id =status"+objArray[i]['id']+">Logout</a>" +
						"</td>" +
						"</tr>";
				sumtext += text;
			}else{
				text = "<tr>"+
				"<td colspan=\"13\" style=\"padding:0;\">"+
				"<table class=\"tablefoot\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" +
				"<tbody>"+
					"<tr>"+
						"<td width=\"33%\" align=\"left\">"+foor_page+"&nbsp;"+
							"<select name=\"selectpage\" onchange=\"showTax()\">"+
							"</select>&nbsp;"+foor_of+"&nbsp;<span id=\"pageAmount\">1</span>"+
						"</td>"+
						"<td width=\"31%\" align=\"center\">"+foor_view+
							"<select name=\"maxEntries\" onchange=\"showTax()\">"+
								"<option style=\"color:#000000\"  value=\"10\">10</option>"+
								"<option style=\"color:#000000\"  value=\"20\">20</option>"+
								"<option style=\"color:#000000\"  value=\"30\">30</option>"+
								"<option style=\"color:#000000\"  value=\"50\">50</option>"+
								"<option style=\"color:#000000\"  value=\"70\">70</option>"+
								"<option style=\"color:#000000\"  value=\"100\">100</option>"+
								"<option style=\"color:#000000\"  value=\"200\">200</option>"+
								"<option style=\"color:#000000\"  value=\"100000\">All</option>"+
							"</select>"+foor_rpp+" </td>" +
							"<td width=\"36%\" align=\"right\"><span id=\"previous\">&lt;&lt;"+foor_pre+"</span> |" +
							" <span id=\"next\">"+foor_next+"&gt;&gt;</span></td></tr>"+
							"</tbody></table></td></tr>";
				sumtext += text;
			}
	}
	$("#showList tr").not($("#showList tr").first()).remove();
	$("#showList").append(sumtext);
	$("#pageAmount").text(pageAmount);
	if(pagePointer+1 <= pageAmount){
		$("#next").attr("onclick","showLoggedIn(id)");
		$("#next").html("<a href=\"#\">Next&gt;&gt;</a>");
	}
	if(pagePointer > 1){
		$("#previous").attr("onclick","showLoggedIn(id)");
		$("#previous").html("<a href=\"#\">&lt;&lt;Previous</a>");
	}
	$("[name=maxEntries]").val(line);
	for ( var i = 0; i < pageAmount; i++) {
		$("[name=selectpage]").append(
				$("<option>").val((i+1)).html((i+1)));
		}
	$("[name=selectpage]").val(pagePointer);
	closeWaitingDialog();
}

function changeStatusLoggedIn(id){
	waitingDialog({});
	var url = "/loginService";
	var data = { func : "logoutById",
			userId : id
		}
	simpleservice(url,data,showLoggedIn);
}

function MultiLogoutUser(){
	waitingDialog({});
	var listCheckBox = "";
	for(var i = 0;i<$('tr [type=checkbox]').not($('tr [type=checkbox]').first()).length;i++){
		if($('tr [type=checkbox]').not($('tr [type=checkbox]').first())[i].checked == true){	
			listCheckBox += $($('tr [type=checkbox]').not($('tr [type=checkbox]').first())[i]).attr("value")+",";
		}
	}
	var url = "/loginService";
	var data = { func : "logoutById",userId : listCheckBox.substring(0,listCheckBox.length - 1)}
	simpleservice(url,data,showLoggedIn);
}

function toggleSelect(){
	if($("#showList tr [type=checkbox]")[0].checked == true){
		for(var i = 0;i< $("#showList tr [type=checkbox]").size();i++){
			$("#showList tr [type=checkbox]")[i].checked = true;
		}
	}else{
		for(var i = 0;i< $("#showList tr [type=checkbox]").size();i++){
			$("#showList tr [type=checkbox]")[i].checked = false;
		}
	}
}